package com.algorithm;

import java.util.ArrayList;
import java.util.List;

/**
 * 不重复字符串
 */
public class WithoutRepeatingCharacters {


    public static int lengthOfLongestSubstring(String s) {
        List<Byte> list=new ArrayList<Byte>();
        int maxCount=0;
        byte[] bytes = s.getBytes();
        for (byte aByte : bytes) {
            while (list.contains(aByte)){
                list.remove(0);
            }
            list.add(aByte);
            if (list.size()>maxCount){
                maxCount=list.size();
            }
        }
        return maxCount;
    }

    public static void main(String[] args) {
        String str="abcabcbb";
//        String str="bbbbb";
//        String str="pwwkew";
//        String str="dvdf";
        int i = lengthOfLongestSubstring(str);
        System.out.println(i);

//        int handsome = 1;
//        int rich = 5;
//        handsome = handsome ^ rich;
//        rich = handsome ^ rich;
//        handsome = rich ^ handsome;
//        System.out.println(handsome);
//        System.out.println(rich);
    }
}
